import Vue from 'vue'
import Router from 'vue-router'
import Index from '@/components/Index'
import Make from '@/components/Make'
import Show from '@/components/Show'
import Login from '@/components/Login'
import My from '@/components/My'
import Page from '@/components/Page'

import {hasSid} from '../../static/js/common.js'
import {wexinsdk} from '../../static/js/wxsdk.js'
Vue.use(Router)

const myrouter=new Router({
  routes: [
    {
      path: '/',
      name: 'Index',
      component: Index
    },
    {
      path: '/make',
      name: 'Make',
      component: Make,
    },
    {
      path: '/show',
      name: 'Show',
      component: Show,
    },
    {
      path: '/login',
      name: 'login',
      component: Login,
    },
    {
      path: '/my',
      name: 'my',
      component: My,
    },
    {
      path: '/page',
      name: 'page',
      component: Page,
    },
    {
      path:'*',
      redirect:'/'
    }
  ]
})
myrouter.beforeEach((to, from, next) => {
  var sid=sessionStorage.getItem('sid')
  if(!sid&&to.name!='login'){
      hasSid()
  }else{
      next()
  }
})
myrouter.afterEach((to, from) => {
  if(to.name=='page'){
    setTimeout(function(){
      wexinsdk()
    },1000)
  }
})

export default myrouter